package com.xhu.collegestudentrentalsystem.config;

import com.xhu.collegestudentrentalsystem.springservice.MyUserDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * @author zhu huilin
 * @date 2023/2/23 20:39
 */
@Configuration
public class SystemSpringSecurityConfig extends WebSecurityConfigurerAdapter {

    // 用户自定义认证
    @Autowired
    private MyUserDetailService myUserDetailService;




    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        // 放过静态资源拦截
        web.ignoring().antMatchers("/resources/**");

        // 放过swagger
        web.ignoring().antMatchers("/actuator/**","/swagger-ui.html",
                "/swagger-resources/**","/webjars/**",
                "/v2/**","/api/**","/error","/doc.html/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        // 关闭csrf防护
        http.csrf().disable();

        // 允许iframe加载页面
        http.headers().frameOptions().sameOrigin();
    }

}
